
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.microweb.toastmaster.webapp.action;


import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.microweb.toastmaster.model.TMProject;
import com.microweb.toastmaster.model.User;
import com.microweb.toastmaster.service.TMProjectManager;
import com.microweb.toastmaster.service.UserManager;
import java.util.ArrayList;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class SpeechProgressController implements Controller {
    private final Log log = LogFactory.getLog(RoleAssignmentController.class);
    private UserManager userManager = null;
    private TMProjectManager TMProjectManager = null;

    public void setUserManager(UserManager userManager) {
        this.userManager = userManager;
    }

    public void setTMProjectManager(TMProjectManager TMProjectManager) {
        this.TMProjectManager = TMProjectManager;
    }

    public ModelAndView handleRequest(HttpServletRequest request,
                                      HttpServletResponse response)
    throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'handleRequest' method...");
        }

        User user = new User();
        user.setEnabled(true);
        List<?> users = userManager.getUsers(user);
        List<?> projects = TMProjectManager.getTMProjects(null);
        // Collections.sort(projects);
        List<Object> projectNames = new ArrayList<Object>();
        for(int i=0; i<projects.size(); i++) {
            TMProject project = (TMProject)projects.get(i);
            projectNames.add(project.getNumber().toString() + "." + project.getName());
        }
        
        ModelAndView mav = new ModelAndView("speechProgress");
        mav.addObject("projectNames", projectNames);
        mav.addObject("userList", users);
        return mav;
    }
}
